{extend name="public:base" /}

{block name="body"}
<div class="row">
    <div class="col-md-8">
        <div class="page-header">
            <h2 class="text-center">用户登录</h2>
            <form class="form-horizontal" method="post" id="login">
                <div class="form-group">
                    <label for="inputEmail2" class="col-sm-2 control-label">邮箱:</label>
                    <div class="col-sm-10">
                        <input type="text" name="email" class="form-control" value="1436393509@qq.com" id="inputEmail2" placeholder="Email">
                    </div>
                </div>

                <div class="form-group">
                    <label for="inputPassword4" class="col-sm-2 control-label">密码:</label>
                    <div class="col-sm-10">
                        <input type="password" name="password" class="form-control" value="123456" id="inputPassword4" placeholder="Password">
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="button" class="btn btn-primary" id="submit">登录</button>
                    </div>
                </div>
            </form>

        </div>
    </div>

    <script type="text/javascript">
        $(function(){
            $('#submit').on('click',function(){
                //用ajax提交用户信息
                $.ajax({
                    type: 'post',
                    url: "{:url('loginCheck')}",
                    data: $('#login').serialize(),
                    dataType: 'json',
                    success: function(data){
                        switch (data.status)
                        {
                            case 1:  //登录成功跳到首页
                                alert(data.message);
                                window.location.href = "{:url('index/index')}";
                                break;
                            case 0:  //失败或验证不通过返回登录页
                            case -1:
                                alert(data.message);
                                window.location.back();
                                break;
                        }

                    }
                })
            })
        })
    </script>
{/block}